package com.szms.mobile.util;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

import com.szms.mobile.repository.BaseRepository;
import com.szms.mobile.repository.SysCfgRepository;
import com.szms.mobile.repository.model.SysCfgModel;

public class SqliteHelper extends SQLiteOpenHelper {
    private  static SQLiteOpenHelper _instance;
    private  static Object lockObj = new Object();

    /**
     * 单例
     * @param context
     * @return
     */
    public static SQLiteOpenHelper Instance(Context context){
        if(_instance==null){
            synchronized (lockObj){
                if (_instance==null){
                    _instance = new SqliteHelper(context);
                }
            }
        }
        return _instance;
    }

    private SqliteHelper(@Nullable Context context) {
        super(context, "szms", null, 1);
    }

    /**
     * 建表
     * @param db The database.
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
         String sqlSysConfig = BaseRepository.createTable(db, SysCfgModel.class);
         db.execSQL(sqlSysConfig);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }


}
